const app = getApp();
Page({
  data: {
    text: '立即登录',
    bt:false,
    img: '../../img/top.png',
  },
  onLoad(){
      this.setData({
        text:wx.getStorageSync('nickName'),
        img:wx.getStorageSync('img')
      })
      if(this.data.text){
        this.data.bt=true
      }
  },
  Login() {
    if(this.data.bt) return false
    let self=this
    wx.getUserProfile({
      desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        this.setData({
          img:res.userInfo.avatarUrl
        }) 
        wx.setStorageSync('img', res.userInfo.avatarUrl);
        let {
          iv,
          encryptedData,
          userInfo,
        } = res;
        wx.login({
          success(res) {
            let {code} = res;
            let param = {iv,encryptedData,userInfo,code};
             app.post("user/login",param).then(res=>{
                self.setData({
                  text:userInfo.nickName,
                })
                wx.setStorageSync('nickName', userInfo.nickName)
               ;
             })
          }
        })
      }
    })
  }

})